import ChatMessage from '../entity/ChatMessage.js'
export default {
  storageMessage(sessionId, messageItem) {
    var list = JSON.parse(wx.getStorageSync(sessionId + "") || "[]")
    list.push(messageItem);
    wx.setStorage({
      data: JSON.stringify(list),
      key: sessionId,
    })
  },
  getStorageMessage(sessionId) {
    return JSON.parse(wx.getStorageSync(sessionId + "") || "[]");
  },

  storageSession(session) {
    wx.setStorage({
      data: JSON.stringify(session),
      key: "h-session-list",
    })
  },

  getSession(session) {
    return JSON.parse(wx.getStorageSync('h-session-list') || "[]")
  },
  /**
   * 创建消息记录
   * @param {*} msg 
   * @param {*} me 
   */
  createMessageItem(msg, me) {
    return new ChatMessage(msg, me)
  }
}
function setDefaultValue(sessionId) {
  var info = wx.getStorageSync("" + sessionId);
  if (info == "") {
    wx.setStorageSync(sessionId, "[]")
  }
}